<!DOCTYPE html>
<html><head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
    <link rel="alternate" type="application/rss+xml" href="/mysql/index.xml" title="h-book" />
    <link rel="canonical" href="/mysql/">

    <title>
        
        MySQL | h-book
        
    </title>

    
    <link href="/css/fontawesome.min.css" rel="stylesheet">

    
    <link rel="stylesheet" href="/css/ace.min.css">

    

    

</head>
<body><nav class="navbar navbar-expand-lg navbar-dark bg-primary shadow sticky-top" id="navbarMain">
    <div class="container">
        <div>
            <a class="navbar-brand" href="/">
                
                h-book
            </a>
        </div>
    </div>
</nav>
<div class="container-fluid">
            <div class="row">

                <div class="docs-sidenav order-0 col-12 col-md-3 col-lg-2 col-xl-2 position-sticky border-right"><nav class="navbar navbar-expand-md navbar-light pl-0">
    <button class="navbar-toggler navbar-toggler-right collapsed" type="button" data-toggle="collapse" data-target="#sidenav-left-collapse" aria-controls="sidenav-left-collapse" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

     <div class="collapse navbar-collapse align-items-start flex-column" id="sidenav-left-collapse">
            <form class="form-inline my-2 my-lg-0 searchbox">
                <input class="form-control mr-sm-2 w-100" data-search-input id="search-by" type="text" placeholder="Search">
            </form>

        

         <ul class="navbar-nav flex-column pt-3">
    <li data-nav-id="/hugo/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/hugo/"><h6>Hugo</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/hugo/init/" class="nav-item my-1">
                
                
                  <a href="/hugo/init/" class="nav-link p-0">
                    init
                  </a>
                
        </li>
        <li data-nav-id="/hugo/add-page/" class="nav-item my-1">
                
                
                  <a href="/hugo/add-page/" class="nav-link p-0">
                    add-page
                  </a>
                
        </li>
        <li data-nav-id="/hugo/edit-skill/" class="nav-item my-1">
                
                
                  <a href="/hugo/edit-skill/" class="nav-link p-0">
                    edit-skill
                  </a>
                
        </li>
        <li data-nav-id="/hugo/publish/" class="nav-item my-1">
                
                
                  <a href="/hugo/publish/" class="nav-link p-0">
                    publish
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/android/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/android/"><h6>Android</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/android/install/" class="nav-item my-1">
                
                
                  <a href="/android/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/android/create-project/" class="nav-item my-1">
                
                
                  <a href="/android/create-project/" class="nav-link p-0">
                    create project
                  </a>
                
        </li>
        <li data-nav-id="/android/import-material/" class="nav-item my-1">
                
                
                  <a href="/android/import-material/" class="nav-link p-0">
                    import material
                  </a>
                
        </li>
        <li data-nav-id="/android/start-page/" class="nav-item my-1">
                
                
                  <a href="/android/start-page/" class="nav-link p-0">
                    startpage
                  </a>
                
        </li>
        <li data-nav-id="/android/i18n/" class="nav-item my-1">
                
                
                  <a href="/android/i18n/" class="nav-link p-0">
                    i18n
                  </a>
                
        </li>
        <li data-nav-id="/android/nav-flat-page/" class="nav-item my-1">
                
                
                  <a href="/android/nav-flat-page/" class="nav-link p-0">
                    nav flat page
                  </a>
                
        </li>
        <li data-nav-id="/android/activity/" class="nav-item my-1">
                
                
                  <a href="/android/activity/" class="nav-link p-0">
                    Activity
                  </a>
                
        </li>
        <li data-nav-id="/android/db/" class="nav-item my-1">
                
                
                  <a href="/android/db/" class="nav-link p-0">
                    DB
                  </a>
                
        </li>
        <li data-nav-id="/android/dialog/" class="nav-item my-1">
                
                
                  <a href="/android/dialog/" class="nav-link p-0">
                    Dialog
                  </a>
                
        </li>
        <li data-nav-id="/android/fragment/" class="nav-item my-1">
                
                
                  <a href="/android/fragment/" class="nav-link p-0">
                    Fragment
                  </a>
                
        </li>
        <li data-nav-id="/android/jetpack/" class="nav-item my-1">
                
                
                  <a href="/android/jetpack/" class="nav-link p-0">
                    Jetpack
                  </a>
                
        </li>
        <li data-nav-id="/android/material/" class="nav-item my-1">
                
                
                  <a href="/android/material/" class="nav-link p-0">
                    Material
                  </a>
                
        </li>
        <li data-nav-id="/android/storage/" class="nav-item my-1">
                
                
                  <a href="/android/storage/" class="nav-link p-0">
                    Storage
                  </a>
                
        </li>
        <li data-nav-id="/android/%E5%9B%BE%E6%A0%87/" class="nav-item my-1">
                
                
                  <a href="/android/%E5%9B%BE%E6%A0%87/" class="nav-link p-0">
                    图标
                  </a>
                
        </li>
        <li data-nav-id="/android/store/" class="nav-item my-1">
                
                
                  <a href="/android/store/" class="nav-link p-0">
                    Store
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/blender/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/blender/"><h6>Blender</h6></a>
        
    </li>
    <li data-nav-id="/bootstrap/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/bootstrap/"><h6>BootStrap</h6></a>
        
    </li>
    <li data-nav-id="/centos7/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/centos7/"><h6>Centos7</h6></a>
        
    </li>
    <li data-nav-id="/dlna/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/dlna/"><h6>DLNA</h6></a>
        
    </li>
    <li data-nav-id="/docker/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/docker/"><h6>Docker</h6></a>
        
    </li>
    <li data-nav-id="/dubbo/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/dubbo/"><h6>Dubbo</h6></a>
        
    </li>
    <li data-nav-id="/ffmpeg/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/ffmpeg/"><h6>FFmpeg</h6></a>
        
    </li>
    <li data-nav-id="/git/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/git/"><h6>Git</h6></a>
        
    </li>
    <li data-nav-id="/gitbook/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/gitbook/"><h6>Gitbook</h6></a>
        
    </li>
    <li data-nav-id="/gitlab/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/gitlab/"><h6>Gitlab</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/gitlab/runner/" class="nav-item my-1">
                
                
                  <a href="/gitlab/runner/" class="nav-link p-0">
                    Runner
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/gradle/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/gradle/"><h6>Gradle</h6></a>
        
    </li>
    <li data-nav-id="/java/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/java/"><h6>Java</h6></a>
        
    </li>
    <li data-nav-id="/jenkins/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/jenkins/"><h6>Jenkins</h6></a>
        
    </li>
    <li data-nav-id="/kubernetes/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/kubernetes/"><h6>Kubernetes</h6></a>
        
    </li>
    <li data-nav-id="/mybatis/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mybatis/"><h6>Mybatis</h6></a>
        
    </li>
    <li data-nav-id="/mybatis-plus/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mybatis-plus/"><h6>Mybatis Plus</h6></a>
        
    </li>
    <li data-nav-id="/mysql/" class="nav-item my-1 active
        ">
        
        
          <a class="nav-link p-0" href="/mysql/"><h6>MySQL</h6></a>
        
    </li>
    <li data-nav-id="/nodejs/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/nodejs/"><h6>Node.js</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/nodejs/npm/" class="nav-item my-1">
                
                
                  <a href="/nodejs/npm/" class="nav-link p-0">
                    NPM
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/postgresql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/postgresql/"><h6>PostgreSQL</h6></a>
        
    </li>
    <li data-nav-id="/redis/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/redis/"><h6>Redis</h6></a>
        
    </li>
    <li data-nav-id="/samba/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/samba/"><h6>Samba</h6></a>
        
    </li>
    <li data-nav-id="/sql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/sql/"><h6>SQL</h6></a>
        
    </li>
    <li data-nav-id="/ue5/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/ue5/"><h6>UE5</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/ue5/install/" class="nav-item my-1">
                
                
                  <a href="/ue5/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/ue5/uninstall/" class="nav-item my-1">
                
                
                  <a href="/ue5/uninstall/" class="nav-link p-0">
                    uninstall
                  </a>
                
        </li>
        <li data-nav-id="/ue5/qa/" class="nav-item my-1">
                
                
                  <a href="/ue5/qa/" class="nav-link p-0">
                    Q&amp;A
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity/"><h6>Unity</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity/install/" class="nav-item my-1">
                
                
                  <a href="/unity/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/unity/scene/" class="nav-item my-1">
                
                
                  <a href="/unity/scene/" class="nav-link p-0">
                    scene
                  </a>
                
        </li>
        <li data-nav-id="/unity/inspector/" class="nav-item my-1">
                
                
                  <a href="/unity/inspector/" class="nav-link p-0">
                    inspector
                  </a>
                
        </li>
        <li data-nav-id="/unity/assets/" class="nav-item my-1">
                
                
                  <a href="/unity/assets/" class="nav-link p-0">
                    assets
                  </a>
                
        </li>
        <li data-nav-id="/unity/audio-source/" class="nav-item my-1">
                
                
                  <a href="/unity/audio-source/" class="nav-link p-0">
                    audio source
                  </a>
                
        </li>
        <li data-nav-id="/unity/camera/" class="nav-item my-1">
                
                
                  <a href="/unity/camera/" class="nav-link p-0">
                    camera
                  </a>
                
        </li>
        <li data-nav-id="/unity/script/" class="nav-item my-1">
                
                
                  <a href="/unity/script/" class="nav-link p-0">
                    script
                  </a>
                
        </li>
        <li data-nav-id="/unity/prefabs/" class="nav-item my-1">
                
                
                  <a href="/unity/prefabs/" class="nav-link p-0">
                    prefabs
                  </a>
                
        </li>
        <li data-nav-id="/unity/physics/" class="nav-item my-1">
                
                
                  <a href="/unity/physics/" class="nav-link p-0">
                    physics
                  </a>
                
        </li>
        <li data-nav-id="/unity/skybox/" class="nav-item my-1">
                
                
                  <a href="/unity/skybox/" class="nav-link p-0">
                    skybox
                  </a>
                
        </li>
        <li data-nav-id="/unity/particle-system/" class="nav-item my-1">
                
                
                  <a href="/unity/particle-system/" class="nav-link p-0">
                    particle system
                  </a>
                
        </li>
        <li data-nav-id="/unity/shortcut-keys/" class="nav-item my-1">
                
                
                  <a href="/unity/shortcut-keys/" class="nav-link p-0">
                    shortcut keys
                  </a>
                
        </li>
        <li data-nav-id="/unity/qa/" class="nav-item my-1">
                
                
                  <a href="/unity/qa/" class="nav-link p-0">
                    Q&amp;A
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-2d-beginner/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-2d-beginner/"><h6>Unity 2D Beginner</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-2d-beginner/init-and-move/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/init-and-move/" class="nav-link p-0">
                    Init &amp; Move
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/map/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/map/" class="nav-link p-0">
                    Map
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/data/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/data/" class="nav-link p-0">
                    Data
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/animate/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/animate/" class="nav-link p-0">
                    Data
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/bullet/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/bullet/" class="nav-link p-0">
                    Bullet
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/cinemachine/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/cinemachine/" class="nav-link p-0">
                    Cinemachine
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/particle/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/particle/" class="nav-link p-0">
                    Particle
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/ui/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/ui/" class="nav-link p-0">
                    UI
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/npc/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/npc/" class="nav-link p-0">
                    NPC
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/sound/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/sound/" class="nav-link p-0">
                    Sound
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-2d-game-kit/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-2d-game-kit/"><h6>Unity 2D Game Kit</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-2d-game-kit/record/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-game-kit/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-3d-beginner/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-3d-beginner/"><h6>Unity 3D Beginner</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-3d-beginner/init/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/level/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/level/" class="nav-link p-0">
                    Level
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/nav/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/nav/" class="nav-link p-0">
                    Nav
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/render-pipeline/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/render-pipeline/" class="nav-link p-0">
                    Render Pipeline
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/postprocessing/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/postprocessing/" class="nav-link p-0">
                    PostProcessing
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/ui/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/ui/" class="nav-link p-0">
                    UI
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/enemy/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/enemy/" class="nav-link p-0">
                    Enemy
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/sound/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/sound/" class="nav-link p-0">
                    Sound
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/%E5%BB%BA%E6%A8%A1%E5%B7%A5%E5%85%B7/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/%E5%BB%BA%E6%A8%A1%E5%B7%A5%E5%85%B7/" class="nav-link p-0">
                    建模工具
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-arpg/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-arpg/"><h6>Unity ARPG</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-arpg/init/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-arpg/role-state-machine/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/role-state-machine/" class="nav-link p-0">
                    Role State Machine
                  </a>
                
        </li>
        <li data-nav-id="/unity-arpg/api-piece/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/api-piece/" class="nav-link p-0">
                    API Piece
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-animation/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-animation/"><h6>Unity Creativecore Animation</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-animation/door/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-animation/door/" class="nav-link p-0">
                    Door
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-animation/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-animation/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-lighting/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-lighting/"><h6>Unity Creativecore Lighting</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-lighting/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-lighting/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-lighting/outdoor/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-lighting/outdoor/" class="nav-link p-0">
                    Outdoor
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-shader/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-shader/"><h6>Unity Creativecore Shader</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-shader/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-shader/glass/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/glass/" class="nav-link p-0">
                    Glass
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-shader/shader-graph/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/shader-graph/" class="nav-link p-0">
                    Shader-Graph
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creator-kit-beginner-code/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creator-kit-beginner-code/"><h6>Unity Creator Kit Beginner Code</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creator-kit-beginner-code/record/" class="nav-item my-1">
                
                
                  <a href="/unity-creator-kit-beginner-code/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creator-kit-fps/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creator-kit-fps/"><h6>Unity Creator Kit FPS</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creator-kit-fps/record/" class="nav-item my-1">
                
                
                  <a href="/unity-creator-kit-fps/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-mythirdperson/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-mythirdperson/"><h6>Unity My Third Person</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-mythirdperson/init/" class="nav-item my-1">
                
                
                  <a href="/unity-mythirdperson/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-playground/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-playground/"><h6>Unity Playground</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-playground/record/" class="nav-item my-1">
                
                
                  <a href="/unity-playground/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-ui/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-ui/"><h6>Unity UI</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-ui/init/" class="nav-item my-1">
                
                
                  <a href="/unity-ui/init/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-vfx/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-vfx/"><h6>Unity VFX</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-vfx/init/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/init/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/bullet/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/bullet/" class="nav-link p-0">
                    bullet
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/rain/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/rain/" class="nav-link p-0">
                    rain
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/rock-rain/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/rock-rain/" class="nav-link p-0">
                    Rock Rain
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/vue/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/vue/"><h6>Vue</h6></a>
        
    </li>
    <li data-nav-id="/web/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/web/"><h6>Web</h6></a>
        
    </li>
        </ul>
    </div>
</nav>


</div>
                <div class="docs-toc large order-lg-2 order-md-0 order-xs-1 col-12 col-lg-2 col-xl-2 position-sticky border-left"><div class="docs-toc">
	<nav id="TableOfContents">
  <ul>
    <li><a href="#java连接配置">Java连接配置</a>
      <ul>
        <li><a href="#5">5</a></li>
        <li><a href="#8">8</a></li>
      </ul>
    </li>
    <li><a href="#命令行连接">命令行连接</a></li>
    <li><a href="#改root的密码">改root的密码</a></li>
    <li><a href="#建库">建库</a></li>
    <li><a href="#建表">建表</a></li>
    <li><a href="#改表名">改表名</a></li>
    <li><a href="#表加字段">表加字段</a></li>
    <li><a href="#修改表字段">修改表字段</a></li>
    <li><a href="#删表字段">删表字段</a></li>
    <li><a href="#删表">删表</a></li>
    <li><a href="#删库">删库</a></li>
    <li><a href="#概念">概念</a></li>
    <li><a href="#数据类型">数据类型</a>
      <ul>
        <li><a href="#数">数</a></li>
        <li><a href="#字符串">字符串</a></li>
        <li><a href="#日期">日期</a></li>
      </ul>
    </li>
    <li><a href="#字段属性">字段属性</a></li>
    <li><a href="#查看已创建的库表结构">查看已创建的库、表、结构</a></li>
    <li><a href="#数据库引擎">数据库引擎</a></li>
    <li><a href="#外键">外键</a></li>
    <li><a href="#insert">insert</a></li>
    <li><a href="#update">update</a></li>
    <li><a href="#delete">delete</a></li>
    <li><a href="#select">select</a></li>
    <li><a href="#事务">事务</a></li>
    <li><a href="#索引">索引</a></li>
    <li><a href="#权限">权限</a></li>
    <li><a href="#备份">备份</a></li>
    <li><a href="#范式">范式</a></li>
    <li><a href="#jdbc">jdbc</a></li>
    <li><a href="#连接池">连接池</a></li>
  </ul>
</nav>
</div>
</div>
                <div class="main col-12 order-1 col-md-9 col-lg-10 col-xl-8 py-3">
                

<div class="d-flex flex-column">
    <h1 class="js-title">MySQL</h1>
    <div class="d-flex align-items-center">
        
    </div>
</div>

<hr>


<h2 id="java连接配置">Java连接配置</h2>
<h3 id="5">5</h3>
<p>url=jdbc:mysql://localhost:3306/dbname?useSSL=false&amp;useUnicode=true&amp;characterEncoding=utf-8</p>
<p>driver-class-name=com.mysql.jdbc.Driver</p>
<h3 id="8">8</h3>
<p>url=jdbc:mysql://localhost:3306/dbname?useSSL=false&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=GMT%2B8</p>
<p>driver-class-name=com.mysql.cj.jdbc.Driver</p>
<h2 id="命令行连接">命令行连接</h2>
<p>-p后面一定不能有空格</p>
<p>mysql -u root -p123456</p>
<h2 id="改root的密码">改root的密码</h2>
<p>update mysql.user set authentication string=password(&lsquo;123456&rsquo;) where user=&lsquo;root&rsquo; and Host=&lsquo;localhost&rsquo;;</p>
<p>flush privileges;</p>
<h2 id="建库">建库</h2>
<p>字符集用utf8，数据库排序用utf8_general_ci</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">create</span> <span style="color:#00a8c8">database</span> <span style="color:#00a8c8">if</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">exists</span> <span style="color:#f92672">`</span><span style="color:#111">mydb</span><span style="color:#f92672">`</span> <span style="color:#111">character</span> <span style="color:#00a8c8">set</span> <span style="color:#111">utf8</span> <span style="color:#00a8c8">collate</span> <span style="color:#111">utf8_general_ci</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">show</span> <span style="color:#111">databases</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#111">use</span> <span style="color:#f92672">`</span><span style="color:#111">mydb</span><span style="color:#f92672">`</span><span style="color:#111">;</span>
</span></span></code></pre></div><h2 id="建表">建表</h2>
<p>引擎用InnoDB，字符集用utf8，核对用utf8_general_ci</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">create</span> <span style="color:#00a8c8">table</span> <span style="color:#00a8c8">if</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">exists</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#111">(</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">id</span><span style="color:#f92672">`</span> <span style="color:#111">int</span><span style="color:#111">(</span><span style="color:#ae81ff">10</span><span style="color:#111">)</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#111">auto_increment</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;id&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#111">varchar</span><span style="color:#111">(</span><span style="color:#ae81ff">100</span><span style="color:#111">)</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#00a8c8">default</span> <span style="color:#d88200">&#39;匿名&#39;</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;姓名&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">age</span><span style="color:#f92672">`</span> <span style="color:#111">int</span><span style="color:#111">(</span><span style="color:#ae81ff">3</span><span style="color:#111">)</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#00a8c8">comment</span> <span style="color:#f92672">`</span><span style="color:#960050;background-color:#1e0010">年龄</span><span style="color:#f92672">`</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">primary</span> <span style="color:#00a8c8">key</span> <span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">id</span><span style="color:#f92672">`</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#111">)</span><span style="color:#111">engine</span><span style="color:#f92672">=</span><span style="color:#111">innodb</span> <span style="color:#00a8c8">default</span> <span style="color:#111">charset</span><span style="color:#f92672">=</span><span style="color:#111">utf8</span> <span style="color:#00a8c8">collate</span><span style="color:#f92672">=</span><span style="color:#111">utf8_general_ci</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">show</span> <span style="color:#111">tables</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">describe</span> <span style="color:#111">mytable</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">insert</span> <span style="color:#00a8c8">into</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">id</span><span style="color:#f92672">`</span><span style="color:#111">,</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span><span style="color:#111">,</span> <span style="color:#f92672">`</span><span style="color:#111">age</span><span style="color:#f92672">`</span><span style="color:#111">)</span> <span style="color:#00a8c8">values</span> <span style="color:#111">(</span><span style="color:#d88200">&#39;1&#39;</span><span style="color:#111">,</span> <span style="color:#d88200">&#39;myname&#39;</span><span style="color:#111">,</span> <span style="color:#d88200">&#39;10&#39;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#f92672">*</span> <span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span><span style="color:#111">;</span>
</span></span></code></pre></div><h2 id="改表名">改表名</h2>
<p>alter table mytable rename as myt;</p>
<h2 id="表加字段">表加字段</h2>
<p>alter table mytable add age int;</p>
<h2 id="修改表字段">修改表字段</h2>
<p>alter table mytable modify age varchar(30); &ndash; 改约束</p>
<p>alter table mytable change age age1 int; &ndash; 重命名</p>
<h2 id="删表字段">删表字段</h2>
<p>alter table mytable drop age;</p>
<h2 id="删表">删表</h2>
<pre tabindex="0"><code>drop table `mytable`;
</code></pre><h2 id="删库">删库</h2>
<pre tabindex="0"><code>drop database if exists `mydb`;
</code></pre><h2 id="概念">概念</h2>
<ul>
<li>DDL 数据库定义语言</li>
<li>DML 数据库操作语言</li>
<li>DQL 数据库查询语言</li>
<li>DCL 数据库控制语言</li>
</ul>
<h2 id="数据类型">数据类型</h2>
<h3 id="数">数</h3>
<ul>
<li>tinyint 1字节</li>
<li>smallint 2字节</li>
<li>mediumint 3字节</li>
<li>int 4字节</li>
<li>bigint 8字节</li>
<li>float 4字节</li>
<li>double 8字节</li>
<li>decimal 字符串形式的浮点数，用于金融计算</li>
</ul>
<h3 id="字符串">字符串</h3>
<ul>
<li>char 0~255</li>
<li>varchar 可变长字符串 0~65535</li>
<li>tinytext 0~2^8-1</li>
<li>text 0~2^16-1</li>
</ul>
<h3 id="日期">日期</h3>
<ul>
<li>date yyyy-MM-DD</li>
<li>time HH:mm:ss</li>
<li>datetime yyyy-MM-DD HH:mm:ss</li>
<li>timestamp 时间戳 1970.1.1到现在的毫秒数</li>
<li>year 年份</li>
</ul>
<h2 id="字段属性">字段属性</h2>
<ul>
<li>Unsigned 无符号整数，此时不能赋值为负数</li>
<li>zerofill 不足的位数，默认0填充。如int(3)赋值5时会是005，这个(3)只是用于显示宽度，与实际int的范围大小无关</li>
<li>auto increment 整数自增</li>
<li>not null 非空</li>
<li>default 默认值</li>
</ul>
<h2 id="查看已创建的库表结构">查看已创建的库、表、结构</h2>
<p>show create database mydb;</p>
<p>show create table mytable;</p>
<p>desc mytable;</p>
<h2 id="数据库引擎">数据库引擎</h2>
<p>innodb 5.7 8.0 默认引擎，安全性高</p>
<p>myisam 节约空间，速度较快</p>
<ul>
<li>myisam不支持事务，innodb支持</li>
<li>myisam表锁，innodb行锁</li>
<li>myisam不支持外键，innodb支持</li>
<li>myisam支持全文索引，老的innodb不支持</li>
<li>表空间的大小，myisam小，innodb大（约2倍）</li>
<li>myisam重启数据库后自增列继续上一个自增量，innodb会从1开始（存于内存中）</li>
</ul>
<p>所有数据库文件在data目录下</p>
<p>innodb下，数据库表中只有.frm是文件，以及上级目录下的ibdata1文件</p>
<p>myisam下，.frm定义表结构，.MYD数据文件，.MYI索引文件</p>
<h2 id="外键">外键</h2>
<p>数据库的物理外键，但阿里就强制不使用外键及其级联，一切外键概念必须在应用层解决</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">create</span> <span style="color:#00a8c8">table</span> <span style="color:#00a8c8">if</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">exists</span> <span style="color:#f92672">`</span><span style="color:#111">grade</span><span style="color:#f92672">`</span> <span style="color:#111">(</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">grade_id</span><span style="color:#f92672">`</span> <span style="color:#111">int</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#111">auto_increment</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;年级id&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">grade_name</span><span style="color:#f92672">`</span> <span style="color:#111">varchar</span><span style="color:#111">(</span><span style="color:#ae81ff">100</span><span style="color:#111">)</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;年级名称&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">primary</span> <span style="color:#00a8c8">key</span> <span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">grade_id</span><span style="color:#f92672">`</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#111">)</span><span style="color:#111">engine</span><span style="color:#f92672">=</span><span style="color:#111">innodb</span> <span style="color:#00a8c8">default</span> <span style="color:#111">charset</span><span style="color:#f92672">=</span><span style="color:#111">utf8</span> <span style="color:#00a8c8">collate</span><span style="color:#f92672">=</span><span style="color:#111">utf8_general_ci</span><span style="color:#111">;</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">create</span> <span style="color:#00a8c8">table</span> <span style="color:#00a8c8">if</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">exists</span> <span style="color:#f92672">`</span><span style="color:#111">student</span><span style="color:#f92672">`</span> <span style="color:#111">(</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">id</span><span style="color:#f92672">`</span> <span style="color:#111">int</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#111">auto_increment</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;学生id&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#111">varchar</span><span style="color:#111">(</span><span style="color:#ae81ff">100</span><span style="color:#111">)</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;学生姓名&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">grade_id</span><span style="color:#f92672">`</span> <span style="color:#111">int</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;学生年级&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">primary</span> <span style="color:#00a8c8">key</span> <span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">id</span><span style="color:#f92672">`</span><span style="color:#111">),</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">key</span> <span style="color:#f92672">`</span><span style="color:#111">fk_grade_id</span><span style="color:#f92672">`</span> <span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">grade_id</span><span style="color:#f92672">`</span><span style="color:#111">),</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">constraint</span> <span style="color:#f92672">`</span><span style="color:#111">fk_grade_id</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">foreign</span> <span style="color:#00a8c8">key</span> <span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">grade_id</span><span style="color:#f92672">`</span><span style="color:#111">)</span> <span style="color:#00a8c8">references</span> <span style="color:#f92672">`</span><span style="color:#111">grade</span><span style="color:#f92672">`</span><span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">grade_id</span><span style="color:#f92672">`</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#111">)</span><span style="color:#111">engine</span><span style="color:#f92672">=</span><span style="color:#111">innodb</span> <span style="color:#00a8c8">default</span> <span style="color:#111">charset</span><span style="color:#f92672">=</span><span style="color:#111">utf8</span> <span style="color:#00a8c8">collate</span><span style="color:#f92672">=</span><span style="color:#111">utf8_general_ci</span><span style="color:#111">;</span>
</span></span></code></pre></div><p>或者</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">create</span> <span style="color:#00a8c8">table</span> <span style="color:#00a8c8">if</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">exists</span> <span style="color:#f92672">`</span><span style="color:#111">student</span><span style="color:#f92672">`</span> <span style="color:#111">(</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">id</span><span style="color:#f92672">`</span> <span style="color:#111">int</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#111">auto_increment</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;学生id&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#111">varchar</span><span style="color:#111">(</span><span style="color:#ae81ff">100</span><span style="color:#111">)</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;学生姓名&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">`</span><span style="color:#111">grade_id</span><span style="color:#f92672">`</span> <span style="color:#111">int</span> <span style="color:#00a8c8">not</span> <span style="color:#00a8c8">null</span> <span style="color:#00a8c8">comment</span> <span style="color:#d88200">&#39;学生年级&#39;</span><span style="color:#111">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">primary</span> <span style="color:#00a8c8">key</span> <span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">id</span><span style="color:#f92672">`</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#111">)</span><span style="color:#111">engine</span><span style="color:#f92672">=</span><span style="color:#111">innodb</span> <span style="color:#00a8c8">default</span> <span style="color:#111">charset</span><span style="color:#f92672">=</span><span style="color:#111">utf8</span> <span style="color:#00a8c8">collate</span><span style="color:#f92672">=</span><span style="color:#111">utf8_general_ci</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">alter</span> <span style="color:#00a8c8">table</span> <span style="color:#f92672">`</span><span style="color:#111">student</span><span style="color:#f92672">`</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">add</span> <span style="color:#00a8c8">constraint</span> <span style="color:#f92672">`</span><span style="color:#111">fk_grade_id</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">foreign</span> <span style="color:#00a8c8">key</span> <span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">grade_id</span><span style="color:#f92672">`</span><span style="color:#111">)</span> <span style="color:#00a8c8">references</span> <span style="color:#f92672">`</span><span style="color:#111">grade</span><span style="color:#f92672">`</span><span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">grade_id</span><span style="color:#f92672">`</span><span style="color:#111">);</span>
</span></span></code></pre></div><h2 id="insert">insert</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">insert</span> <span style="color:#00a8c8">into</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span><span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span><span style="color:#111">,</span> <span style="color:#f92672">`</span><span style="color:#111">age</span><span style="color:#f92672">`</span><span style="color:#111">)</span> <span style="color:#00a8c8">values</span><span style="color:#111">(</span><span style="color:#d88200">&#39;zzz&#39;</span><span style="color:#111">,</span> <span style="color:#d88200">&#39;20&#39;</span><span style="color:#111">);</span>
</span></span></code></pre></div><h2 id="update">update</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">update</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">set</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;xxx&#39;</span><span style="color:#111">,</span> <span style="color:#f92672">`</span><span style="color:#111">age</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;33&#39;</span> <span style="color:#00a8c8">where</span> <span style="color:#111">id</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span><span style="color:#111">;</span> <span style="color:#75715e">-- = &lt;&gt; != &lt; &gt; &lt;= &gt;=
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">update</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">set</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;xxx&#39;</span><span style="color:#111">,</span> <span style="color:#f92672">`</span><span style="color:#111">age</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;33&#39;</span> <span style="color:#00a8c8">where</span> <span style="color:#111">id</span> <span style="color:#00a8c8">between</span> <span style="color:#ae81ff">2</span> <span style="color:#00a8c8">and</span> <span style="color:#ae81ff">5</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">update</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">set</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;xxx&#39;</span><span style="color:#111">,</span> <span style="color:#f92672">`</span><span style="color:#111">age</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;33&#39;</span> <span style="color:#00a8c8">where</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;yy&#39;</span> <span style="color:#00a8c8">and</span> <span style="color:#111">age</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;20&#39;</span><span style="color:#111">;</span> <span style="color:#75715e">-- and or
</span></span></span></code></pre></div><h2 id="delete">delete</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">delete</span> <span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">where</span> <span style="color:#111">id</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">truncate</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span><span style="color:#111">;</span> <span style="color:#75715e">-- 重新设置自增列的计数，不会影响事务
</span></span></span></code></pre></div><h2 id="select">select</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#f92672">*</span> <span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">my_name</span> <span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">mt</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#111">concat</span><span style="color:#111">(</span><span style="color:#d88200">&#39;姓名：&#39;</span><span style="color:#111">,</span> <span style="color:#111">name</span><span style="color:#111">)</span> <span style="color:#00a8c8">as</span> <span style="color:#111">my_name</span> <span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span><span style="color:#111">;</span> <span style="color:#75715e">-- 会将name列的值都首拼接 姓名：
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#00a8c8">distinct</span> <span style="color:#f92672">`</span><span style="color:#111">id</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span><span style="color:#111">;</span> <span style="color:#75715e">-- 去重
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#f92672">`</span><span style="color:#00a8c8">result</span><span style="color:#f92672">`+</span><span style="color:#ae81ff">1</span> <span style="color:#00a8c8">as</span> <span style="color:#d88200">&#39;add_res_one&#39;</span> <span style="color:#111">frome</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span><span style="color:#111">;</span> <span style="color:#75715e">-- 所有result都加1
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#ae81ff">100</span><span style="color:#f92672">*</span><span style="color:#ae81ff">3</span><span style="color:#f92672">-</span><span style="color:#ae81ff">1</span> <span style="color:#00a8c8">as</span> <span style="color:#111">res</span><span style="color:#111">;</span> <span style="color:#75715e">-- 用于计算
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#f92672">@@</span><span style="color:#111">auto_increment_increment</span><span style="color:#111">;</span> <span style="color:#75715e">-- 查自增步长
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">where</span> <span style="color:#111">name</span> <span style="color:#00a8c8">like</span> <span style="color:#d88200">&#39;x%&#39;</span><span style="color:#111">;</span> <span style="color:#75715e">-- x开头的name，或者&#39;%x&#39;是x结尾的，或者&#39;x_&#39;是x开头两位长度的（_有多少就是多少长度）
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">where</span> <span style="color:#111">id</span> <span style="color:#00a8c8">in</span> <span style="color:#111">(</span><span style="color:#ae81ff">1</span><span style="color:#111">,</span><span style="color:#ae81ff">2</span><span style="color:#111">,</span><span style="color:#ae81ff">3</span><span style="color:#111">,</span><span style="color:#ae81ff">4</span><span style="color:#111">,</span><span style="color:#ae81ff">5</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#111">frome</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">where</span> <span style="color:#111">addres</span><span style="color:#f92672">=</span><span style="color:#d88200">&#39;&#39;</span> <span style="color:#00a8c8">or</span> <span style="color:#111">address</span> <span style="color:#00a8c8">is</span> <span style="color:#00a8c8">null</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- 如果表中至少有一个匹配，就返回行
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#00a8c8">select</span> <span style="color:#111">ta</span><span style="color:#111">.</span><span style="color:#111">c1</span><span style="color:#111">,</span> <span style="color:#111">c2</span><span style="color:#111">,</span> <span style="color:#111">c3</span><span style="color:#111">,</span> <span style="color:#111">c4</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable_a</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">ta</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">inner</span> <span style="color:#00a8c8">join</span> <span style="color:#f92672">`</span><span style="color:#111">mytable_b</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">tb</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">on</span> <span style="color:#111">ta</span><span style="color:#111">.</span><span style="color:#111">c1</span> <span style="color:#f92672">=</span> <span style="color:#111">tb</span><span style="color:#111">.</span><span style="color:#111">c1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- 左表中返回所有值，即使右边中没有匹配
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#00a8c8">select</span> <span style="color:#111">ta</span><span style="color:#111">.</span><span style="color:#111">c1</span><span style="color:#111">,</span> <span style="color:#111">c2</span><span style="color:#111">,</span> <span style="color:#111">c3</span><span style="color:#111">,</span> <span style="color:#111">c4</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable_a</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">ta</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">left</span> <span style="color:#00a8c8">join</span> <span style="color:#f92672">`</span><span style="color:#111">mytable_b</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">tb</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">on</span> <span style="color:#111">ta</span><span style="color:#111">.</span><span style="color:#111">c1</span> <span style="color:#f92672">=</span> <span style="color:#111">tb</span><span style="color:#111">.</span><span style="color:#111">c1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- 右表中返回所有值，即使左边中没有匹配
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#00a8c8">select</span> <span style="color:#111">ta</span><span style="color:#111">.</span><span style="color:#111">c1</span><span style="color:#111">,</span> <span style="color:#111">c2</span><span style="color:#111">,</span> <span style="color:#111">c3</span><span style="color:#111">,</span> <span style="color:#111">c4</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable_a</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">ta</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">right</span> <span style="color:#00a8c8">join</span> <span style="color:#f92672">`</span><span style="color:#111">mytable_b</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">tb</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">on</span> <span style="color:#111">ta</span><span style="color:#111">.</span><span style="color:#111">c1</span> <span style="color:#f92672">=</span> <span style="color:#111">tb</span><span style="color:#111">.</span><span style="color:#111">c1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#111">ta</span><span style="color:#111">.</span><span style="color:#111">c1</span><span style="color:#111">,</span> <span style="color:#111">c2</span><span style="color:#111">,</span> <span style="color:#111">c3</span><span style="color:#111">,</span> <span style="color:#111">c4</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable_a</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">ta</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">left</span> <span style="color:#00a8c8">join</span> <span style="color:#f92672">`</span><span style="color:#111">mytable_b</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">tb</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">on</span> <span style="color:#111">ta</span><span style="color:#111">.</span><span style="color:#111">c1</span> <span style="color:#f92672">=</span> <span style="color:#111">tb</span><span style="color:#111">.</span><span style="color:#111">c1</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">where</span> <span style="color:#111">c3</span> <span style="color:#00a8c8">is</span> <span style="color:#00a8c8">null</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#111">s</span><span style="color:#111">.</span><span style="color:#111">sNo</span><span style="color:#111">,</span> <span style="color:#111">sName</span><span style="color:#111">,</span> <span style="color:#111">bName</span><span style="color:#111">,</span> <span style="color:#111">sRes</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">from</span> <span style="color:#111">student</span> <span style="color:#111">s</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">right</span> <span style="color:#00a8c8">join</span> <span style="color:#00a8c8">result</span> <span style="color:#111">r</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">on</span> <span style="color:#111">r</span><span style="color:#111">.</span><span style="color:#111">sNo</span> <span style="color:#f92672">=</span> <span style="color:#111">s</span><span style="color:#111">.</span><span style="color:#111">sNo</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">inner</span> <span style="color:#00a8c8">join</span> <span style="color:#f92672">`</span><span style="color:#111">subject</span><span style="color:#f92672">`</span> <span style="color:#111">b</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">on</span> <span style="color:#111">b</span><span style="color:#111">.</span><span style="color:#111">sNo</span> <span style="color:#f92672">=</span> <span style="color:#111">r</span><span style="color:#111">.</span><span style="color:#111">sNo</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- 自连接
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#00a8c8">select</span> <span style="color:#111">a</span><span style="color:#111">.</span><span style="color:#111">name</span> <span style="color:#00a8c8">as</span> <span style="color:#d88200">&#39;p&#39;</span><span style="color:#111">,</span> <span style="color:#111">b</span><span style="color:#111">.</span><span style="color:#111">name</span> <span style="color:#00a8c8">as</span> <span style="color:#d88200">&#39;c&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">from</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">a</span><span style="color:#111">,</span> <span style="color:#f92672">`</span><span style="color:#111">mytable</span><span style="color:#f92672">`</span> <span style="color:#00a8c8">as</span> <span style="color:#111">b</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">where</span> <span style="color:#111">a</span><span style="color:#111">.</span><span style="color:#111">id</span> <span style="color:#f92672">=</span> <span style="color:#111">b</span><span style="color:#111">.</span><span style="color:#111">pid</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#111">age</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span> <span style="color:#00a8c8">where</span> <span style="color:#111">id</span> <span style="color:#f92672">!=</span> <span style="color:#ae81ff">1</span> <span style="color:#00a8c8">order</span> <span style="color:#00a8c8">by</span> <span style="color:#111">age</span><span style="color:#111">;</span> <span style="color:#75715e">-- ....age desc/asc降序/升序
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#111">age</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span> <span style="color:#00a8c8">where</span> <span style="color:#111">id</span> <span style="color:#f92672">!=</span> <span style="color:#ae81ff">1</span> <span style="color:#00a8c8">order</span> <span style="color:#00a8c8">by</span> <span style="color:#111">age</span> <span style="color:#00a8c8">limit</span> <span style="color:#ae81ff">0</span><span style="color:#111">,</span> <span style="color:#ae81ff">5</span><span style="color:#111">;</span> <span style="color:#75715e">--从第一个到第五个
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#111">c1</span><span style="color:#111">,</span> <span style="color:#111">c2</span><span style="color:#111">,</span> <span style="color:#111">c3</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span> <span style="color:#00a8c8">where</span> <span style="color:#111">c2</span> <span style="color:#f92672">=</span> <span style="color:#111">(</span> <span style="color:#00a8c8">select</span> <span style="color:#111">c2</span> <span style="color:#00a8c8">from</span> <span style="color:#111">myt</span> <span style="color:#00a8c8">where</span> <span style="color:#111">s_name</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;abc&#39;</span> <span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#00a8c8">char_length</span><span style="color:#111">(</span><span style="color:#d88200">&#39;字符串的长度&#39;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#00a8c8">count</span><span style="color:#111">(</span><span style="color:#111">id</span><span style="color:#111">)</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span><span style="color:#111">;</span> <span style="color:#75715e">-- 会忽略所有的null
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#00a8c8">count</span><span style="color:#111">(</span><span style="color:#f92672">*</span><span style="color:#111">)</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span><span style="color:#111">;</span> <span style="color:#75715e">-- 不忽略null，计算行
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#111">cout</span><span style="color:#111">(</span><span style="color:#ae81ff">1</span><span style="color:#111">)</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span><span style="color:#111">;</span> <span style="color:#75715e">-- 不忽略null，计算行
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#111">s_name</span><span style="color:#111">,</span> <span style="color:#00a8c8">avg</span><span style="color:#111">(</span><span style="color:#111">res</span><span style="color:#111">)</span> <span style="color:#00a8c8">as</span> <span style="color:#111">p</span><span style="color:#111">,</span> <span style="color:#00a8c8">max</span><span style="color:#111">(</span><span style="color:#111">res</span><span style="color:#111">),</span> <span style="color:#00a8c8">min</span><span style="color:#111">(</span><span style="color:#111">res</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">from</span> <span style="color:#00a8c8">result</span> <span style="color:#111">r</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">inner</span> <span style="color:#00a8c8">join</span> <span style="color:#111">sub</span> <span style="color:#111">b</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">on</span> <span style="color:#111">r</span><span style="color:#111">.</span><span style="color:#111">s_no</span> <span style="color:#f92672">=</span> <span style="color:#111">b</span><span style="color:#111">.</span><span style="color:#111">s_no</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">group</span> <span style="color:#00a8c8">by</span> <span style="color:#111">r</span><span style="color:#111">.</span><span style="color:#111">s_no</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">having</span> <span style="color:#111">p</span> <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">80</span>
</span></span></code></pre></div><h2 id="事务">事务</h2>
<p>acid</p>
<ul>
<li>
<p>a 原子性</p>
</li>
<li>
<p>c 一致性</p>
</li>
<li>
<p>i 隔离性</p>
</li>
<li>
<p>d 持久性</p>
</li>
<li>
<p>脏读：读到另外事务未提交的数据</p>
</li>
<li>
<p>不可重复读：重复读数据，但数值不一致</p>
</li>
<li>
<p>幻读：重复读数据，但条数不一致</p>
</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">set</span> <span style="color:#111">autocommit</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span><span style="color:#111">;</span> <span style="color:#75715e">-- 关闭自动提交
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#00a8c8">start</span> <span style="color:#00a8c8">transaction</span><span style="color:#111">;</span> <span style="color:#75715e">-- 开始事务
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#00a8c8">update</span> <span style="color:#111">account</span> <span style="color:#00a8c8">set</span> <span style="color:#111">money</span><span style="color:#f92672">=</span><span style="color:#111">money</span><span style="color:#f92672">-</span><span style="color:#ae81ff">500</span> <span style="color:#00a8c8">where</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;a&#39;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">update</span> <span style="color:#111">account</span> <span style="color:#00a8c8">set</span> <span style="color:#111">money</span><span style="color:#f92672">=</span><span style="color:#111">money</span><span style="color:#f92672">+</span><span style="color:#ae81ff">500</span> <span style="color:#00a8c8">where</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;b&#39;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">commit</span><span style="color:#111">;</span> <span style="color:#75715e">-- 提交
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">rollback</span><span style="color:#111">;</span> <span style="color:#75715e">-- 回滚
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#00a8c8">set</span> <span style="color:#111">autocommit</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span><span style="color:#111">;</span> <span style="color:#75715e">-- 开启自动提交
</span></span></span></code></pre></div><h2 id="索引">索引</h2>
<p>索引是能帮助高效获取数据的数据结构</p>
<ul>
<li>主键索引 primary 唯一标识</li>
<li>唯一索引 unique 索引列的所有值都只能出现一次，即必须​​唯一​​，值可以为​​空</li>
<li>常规索引 key/index</li>
<li>全文索引 fulltext</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">show</span> <span style="color:#00a8c8">index</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">alter</span> <span style="color:#00a8c8">table</span> <span style="color:#111">mytable</span> <span style="color:#00a8c8">add</span> <span style="color:#111">fulltext</span> <span style="color:#00a8c8">index</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span><span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span><span style="color:#111">);</span> <span style="color:#75715e">-- 索引名(列名)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">explain</span> <span style="color:#00a8c8">select</span> <span style="color:#f92672">*</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span> <span style="color:#75715e">-- explain分析sql执行的状况
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">explain</span> <span style="color:#00a8c8">select</span> <span style="color:#f92672">*</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span> <span style="color:#00a8c8">where</span> <span style="color:#00a8c8">match</span><span style="color:#111">(</span><span style="color:#111">name</span><span style="color:#111">)</span> <span style="color:#111">against</span><span style="color:#111">(</span><span style="color:#d88200">&#39;a&#39;</span><span style="color:#111">);</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">delimiter</span> <span style="color:#960050;background-color:#1e0010">$$</span> <span style="color:#75715e">-- 写函数之前必须写的标志
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">create</span> <span style="color:#00a8c8">function</span> <span style="color:#111">mock_data</span><span style="color:#111">()</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">returns</span> <span style="color:#111">int</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">begin</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">declare</span> <span style="color:#111">num</span> <span style="color:#111">int</span> <span style="color:#00a8c8">default</span> <span style="color:#ae81ff">1000000</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">declare</span> <span style="color:#111">i</span> <span style="color:#111">int</span> <span style="color:#00a8c8">default</span> <span style="color:#ae81ff">0</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">while</span> <span style="color:#111">i</span> <span style="color:#f92672">&lt;</span> <span style="color:#111">num</span> <span style="color:#00a8c8">do</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">insert</span> <span style="color:#00a8c8">into</span> <span style="color:#111">mytable</span> <span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span><span style="color:#111">)</span> <span style="color:#00a8c8">values</span><span style="color:#111">(</span><span style="color:#111">concat</span><span style="color:#111">(</span><span style="color:#d88200">&#39;用户&#39;</span><span style="color:#111">,</span> <span style="color:#111">i</span><span style="color:#111">));</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">set</span> <span style="color:#111">i</span> <span style="color:#f92672">=</span> <span style="color:#111">i</span><span style="color:#f92672">+</span><span style="color:#ae81ff">1</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">end</span> <span style="color:#111">while</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">return</span> <span style="color:#111">i</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">end</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">select</span> <span style="color:#111">mock_data</span><span style="color:#111">();</span> <span style="color:#75715e">-- 上面是定义行数，这里是执行函数
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">explain</span> <span style="color:#00a8c8">select</span> <span style="color:#f92672">*</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span> <span style="color:#00a8c8">where</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;用户9998&#39;</span><span style="color:#111">;</span> <span style="color:#75715e">-- 1秒左右
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">create</span> <span style="color:#00a8c8">index</span> <span style="color:#111">mytable_name</span> <span style="color:#00a8c8">on</span> <span style="color:#111">mytable</span><span style="color:#111">(</span><span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">explain</span> <span style="color:#00a8c8">select</span> <span style="color:#f92672">*</span> <span style="color:#00a8c8">from</span> <span style="color:#111">mytable</span> <span style="color:#00a8c8">where</span> <span style="color:#f92672">`</span><span style="color:#111">name</span><span style="color:#f92672">`</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#39;用户9998&#39;</span><span style="color:#111">;</span> <span style="color:#75715e">-- 0.001秒
</span></span></span></code></pre></div><h2 id="权限">权限</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#111">mysql</span><span style="color:#111">.</span><span style="color:#00a8c8">user</span> <span style="color:#960050;background-color:#1e0010">表</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">create</span> <span style="color:#00a8c8">user</span> <span style="color:#111">myuser</span> <span style="color:#111">identified</span> <span style="color:#00a8c8">by</span> <span style="color:#d88200">&#39;123456&#39;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">set</span> <span style="color:#111">password</span> <span style="color:#f92672">=</span> <span style="color:#111">password</span><span style="color:#111">(</span><span style="color:#d88200">&#39;111111&#39;</span><span style="color:#111">);</span> <span style="color:#75715e">-- 对当前用户设密码
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">set</span> <span style="color:#111">password</span> <span style="color:#00a8c8">for</span> <span style="color:#111">myuser</span> <span style="color:#f92672">=</span> <span style="color:#111">password</span><span style="color:#111">(</span><span style="color:#d88200">&#39;111111&#39;</span><span style="color:#111">);</span> <span style="color:#75715e">-- 对指定用户设密码
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">rename</span> <span style="color:#00a8c8">user</span> <span style="color:#111">myuser</span> <span style="color:#00a8c8">to</span> <span style="color:#111">myu</span><span style="color:#111">;</span> <span style="color:#75715e">-- 改用户名
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">grant</span> <span style="color:#00a8c8">all</span> <span style="color:#00a8c8">privileges</span> <span style="color:#00a8c8">on</span> <span style="color:#f92672">*</span><span style="color:#111">.</span><span style="color:#f92672">*</span> <span style="color:#00a8c8">to</span> <span style="color:#111">myu</span><span style="color:#111">;</span> <span style="color:#75715e">-- 授权所有库、表给myu
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">show</span> <span style="color:#00a8c8">grant</span> <span style="color:#00a8c8">for</span> <span style="color:#111">myu</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">revoke</span> <span style="color:#00a8c8">all</span> <span style="color:#00a8c8">privileges</span> <span style="color:#00a8c8">on</span> <span style="color:#f92672">*</span><span style="color:#111">.</span><span style="color:#f92672">*</span> <span style="color:#00a8c8">from</span> <span style="color:#111">myu</span><span style="color:#111">;</span> <span style="color:#75715e">-- 撤销权限
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">drop</span> <span style="color:#00a8c8">user</span> <span style="color:#111">myu</span><span style="color:#111">;</span>
</span></span></code></pre></div><h2 id="备份">备份</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#111">mysqldump</span> <span style="color:#f92672">-</span><span style="color:#111">hlocalhost</span> <span style="color:#f92672">-</span><span style="color:#111">uroot</span> <span style="color:#f92672">-</span><span style="color:#111">p123456</span> <span style="color:#111">mydb</span> <span style="color:#111">mytable</span> <span style="color:#111">mytable2</span> <span style="color:#111">mytable3</span> <span style="color:#f92672">&gt;</span> <span style="color:#111">D</span><span style="color:#111">:</span><span style="color:#f92672">/</span><span style="color:#111">a</span><span style="color:#111">.</span><span style="color:#00a8c8">sql</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">user</span> <span style="color:#111">mydb</span><span style="color:#111">;</span> <span style="color:#00a8c8">source</span> <span style="color:#111">D</span><span style="color:#111">:</span><span style="color:#f92672">/</span><span style="color:#111">a</span><span style="color:#111">.</span><span style="color:#00a8c8">sql</span><span style="color:#111">;</span>
</span></span></code></pre></div><h2 id="范式">范式</h2>
<ul>
<li>一：字段原子性，不可再分</li>
<li>二：每个字段都要和主键相关，且在第一范式基础之上</li>
<li>三：每个字段都要和主键直接相关，且在第二范式基础之上</li>
</ul>
<h2 id="jdbc">jdbc</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">class</span> <span style="color:#75af00">T</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">void</span> <span style="color:#75af00">t</span><span style="color:#111">()</span> <span style="color:#00a8c8">throws</span> <span style="color:#111">Exception</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">Class</span><span style="color:#111">.</span><span style="color:#75af00">forName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;com.mysql.jdbc.Driver&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 加载驱动</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">String</span> <span style="color:#111">url</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#34;jdbc:mysql://localhost:3306/mydb?useSSL=false&amp;useUnicode=true&amp;characterEncoding=utf-8&#34;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">String</span> <span style="color:#111">username</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#34;root&#34;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">String</span> <span style="color:#111">password</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#34;123456&#34;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">Connection</span> <span style="color:#111">connection</span> <span style="color:#f92672">=</span> <span style="color:#111">DriverManager</span><span style="color:#111">.</span><span style="color:#75af00">getConnection</span><span style="color:#111">(</span><span style="color:#111">url</span><span style="color:#111">,</span> <span style="color:#111">username</span><span style="color:#111">,</span> <span style="color:#111">password</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">Statement</span> <span style="color:#111">statement</span> <span style="color:#f92672">=</span> <span style="color:#111">connection</span><span style="color:#111">.</span><span style="color:#75af00">createStatement</span><span style="color:#111">();</span> <span style="color:#75715e">// 会存在SQL注入的问题</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">String</span> <span style="color:#111">sql</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#34;select * from mytable&#34;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">ResultSet</span> <span style="color:#111">resultSet</span> <span style="color:#f92672">=</span> <span style="color:#111">statement</span><span style="color:#111">.</span><span style="color:#75af00">executeQuery</span><span style="color:#111">(</span><span style="color:#111">sql</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">//statement.executeQuery(sql); // 更新、插入、删除，返回受影响的行数</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">//statement.execute(sql); // 执行任何sql</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">while</span> <span style="color:#111">(</span><span style="color:#111">resultSet</span><span style="color:#111">.</span><span style="color:#75af00">next</span><span style="color:#111">())</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">System</span><span style="color:#111">.</span><span style="color:#75af00">out</span><span style="color:#111">.</span><span style="color:#75af00">println</span><span style="color:#111">(</span><span style="color:#d88200">&#34;id=&#34;</span> <span style="color:#f92672">+</span> <span style="color:#111">resultSet</span><span style="color:#111">.</span><span style="color:#75af00">getObject</span><span style="color:#111">(</span><span style="color:#d88200">&#34;id&#34;</span><span style="color:#111">));</span> <span style="color:#75715e">// resultSet.getInt();</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">System</span><span style="color:#111">.</span><span style="color:#75af00">out</span><span style="color:#111">.</span><span style="color:#75af00">println</span><span style="color:#111">(</span><span style="color:#d88200">&#34;name=&#34;</span> <span style="color:#f92672">+</span> <span style="color:#111">resultSet</span><span style="color:#111">.</span><span style="color:#75af00">getObject</span><span style="color:#111">(</span><span style="color:#d88200">&#34;name&#34;</span><span style="color:#111">));</span> <span style="color:#75715e">// resultSet.getString();</span>
</span></span><span style="display:flex;"><span>      <span style="color:#111">System</span><span style="color:#111">.</span><span style="color:#75af00">out</span><span style="color:#111">.</span><span style="color:#75af00">println</span><span style="color:#111">(</span><span style="color:#d88200">&#34;pwd=&#34;</span> <span style="color:#f92672">+</span> <span style="color:#111">resultSet</span><span style="color:#111">.</span><span style="color:#75af00">getObject</span><span style="color:#111">(</span><span style="color:#d88200">&#34;pwd&#34;</span><span style="color:#111">));</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// 用这个</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">connection</span><span style="color:#111">.</span><span style="color:#75af00">setAutoCommit</span><span style="color:#111">(</span><span style="color:#00a8c8">false</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">String</span> <span style="color:#111">sql2</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#34;insert into myable(id, `name`, `pwd`) valuse(?,?,?)&#34;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">PrepareStatement</span> <span style="color:#111">prepareStatement</span> <span style="color:#f92672">=</span> <span style="color:#111">connection</span><span style="color:#111">.</span><span style="color:#75af00">createPrepareStatement</span><span style="color:#111">(</span><span style="color:#111">sql2</span><span style="color:#111">);</span> <span style="color:#75715e">// 不会被SQL注入</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">prepareStatement</span><span style="color:#111">.</span><span style="color:#75af00">setInt</span><span style="color:#111">(</span><span style="color:#111">1</span><span style="color:#111">,</span> <span style="color:#111">1</span><span style="color:#111">);</span> <span style="color:#75715e">// 第一个问号，用1替换</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">prepareStatement</span><span style="color:#111">.</span><span style="color:#75af00">setString</span><span style="color:#111">(</span><span style="color:#111">2</span><span style="color:#111">,</span> <span style="color:#d88200">&#34;ab&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">prepareStatement</span><span style="color:#111">.</span><span style="color:#75af00">setString</span><span style="color:#111">(</span><span style="color:#111">3</span><span style="color:#111">,</span> <span style="color:#d88200">&#34;123456&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">int</span> <span style="color:#111">i</span> <span style="color:#f92672">=</span> <span style="color:#111">prepareStatement</span><span style="color:#111">.</span><span style="color:#75af00">executeUpdate</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">connection</span><span style="color:#111">.</span><span style="color:#75af00">commit</span><span style="color:#111">();</span> <span style="color:#75715e">//connection.rollback(); // try catch中的catch里调用（不写也会默认回滚）</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">resultSet</span><span style="color:#111">.</span><span style="color:#75af00">close</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">statement</span><span style="color:#111">.</span><span style="color:#75af00">close</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">prepareStatement</span><span style="color:#111">.</span><span style="color:#75af00">close</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">connection</span><span style="color:#111">.</span><span style="color:#75af00">close</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="连接池">连接池</h2>
<ul>
<li>最小连接数</li>
<li>最大连接数</li>
<li>等待超时</li>
</ul>
<p>写连接池就实现DataSource接口</p>


    


                    
                    <div class="row"></div> 

                </div>

            </div> 

        </div> 
<script src="/lib/jquery.min.js"></script> 
<script src="/lib/popper.min.js"></script> 

<script src="/js/bootstrap.min.js"></script> 


<script type="text/javascript" src="/plugins/lunr.min.js"></script>
<script type="text/javascript" src="/plugins/auto-complete.js"></script>
<link href="/plugins/auto-complete.css" rel="stylesheet">
<script type="text/javascript">
  
      var baseurl = "\/";
  
</script>
<script type="text/javascript" src="/plugins/search.js"></script>

<script type="text/javascript" src="/plugins/favorites.js"></script>


<script type="text/javascript" src="/plugins/clipboard.js"></script>
<script>
  new ClipboardJS('.btn');
</script>
</body>
</html>
